﻿package  {
	
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	
	public class Main extends MovieClip {
		
		private var firstX:Number;
		private var iBiao:int = 1;
		private var oldiBiao:int = 1;
		private var addX:Number = 25;
		private var isLeft:Boolean = true;
		private var iNumber:int;
		private var arrXY:Array = [[366.1,578.1],[342.1,600.1],[312.1,630.1]];
		public function Main() {
			// constructor code
			this.addEventListener(Event.ADDED_TO_STAGE, addet);
		}
		private function addet(e:Event) {
			TweenLite.delayedCall(5,startGame);
		}
		private function startGame() {
			mcMark.visible = false;
			btn1.addEventListener(MouseEvent.MOUSE_DOWN, startCheck);
			btn2.addEventListener(MouseEvent.MOUSE_DOWN, startCheck);
			btn1.buttonMode = true;
			btn2.buttonMode = true;
			stage.addEventListener(MouseEvent.MOUSE_UP, stopCheck);
			gotoPart(1);
		}
		private function stopCheck(e:MouseEvent) {
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, msMove);
		}
		private function startCheck(e:MouseEvent) {
			var mct = e.currentTarget;
			var num:int = int(String(mct.name).charAt(3));
			isLeft = (num == 1)?true:false;
			firstX = mouseX;
			stage.addEventListener(MouseEvent.MOUSE_MOVE, msMove);
			//iBiao++;
			//if (iBiao > 3) iBiao = 1;
			//gotoPart(iBiao);
		}
		private function msMove(e:MouseEvent) {
			//if()
			PD();
		}
		private function PD() {
			iNumber = (isLeft)? -1:1;
			if ((mouseX - firstX) > addX) {
				firstX = mouseX;
				iBiao += iNumber;
				if (iBiao < 1) iBiao = 1;
				if (iBiao > 3) iBiao = 3;
				gotoPart(iBiao);
			}
			if ((firstX-mouseX) > addX) {
				firstX = mouseX;
				iBiao-=iNumber;
				if (iBiao < 1) iBiao = 1;
				if (iBiao > 3) iBiao = 3;
				gotoPart(iBiao);
			}
		}
		private function gotoPart(value:int) {
			//iBiao = value;
			if (iBiao == oldiBiao) return;
			oldiBiao = iBiao;
			var time:Number = 0.8;
			addChild(this["mc" + value]);
			addChild(btn1);
			addChild(btn2);
			btn1.x = arrXY[iBiao - 1][0];
			btn2.x = arrXY[iBiao - 1][1];
			//TweenMax.killAll(true);
			TweenLite.to(this["mc" + value], time, { alpha:1 } );
			var num1:int = (value+1) % 3;
			num1 = (num1 == 0)?3:num1;
			TweenLite.to(this["mc" + num1], time, { alpha:0 } );
			num1 = (value+2) % 3;
			num1 = (num1 == 0)?3:num1;
			TweenLite.to(this["mc" + num1], time, { alpha:0 } );
			
		}
	}
	
}
